package com.ruoyi.user.controller;


import com.ruoyi.user.domain.*;
import com.ruoyi.user.service.UserInfoService;
import com.ruoyi.user.utils.AliPicUtils;
import com.ruoyi.user.utils.SfzUtis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;

@RequestMapping("/user")
@RestController
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private RedisTemplate redisTemplate;


    @RequestMapping("/sendCode")
    //注册验证码
    public ResultVo sendCode(String phone){
            return userInfoService.sendCode(phone);
    }
    @RequestMapping("/loginCode")
    //登录验证码和修改验证码
    public ResultVo loginCode(String phone){
        return userInfoService.loginCode(phone);
    }

    //登录
    @RequestMapping("/getshow")
    public ResultVo getshow(@RequestBody UserInfo userInfo){
        return userInfoService.getshow(userInfo);
    }
    //注册
    @RequestMapping("/add")
    public ResultVo add(@RequestBody UserInfo userInfo){
        return userInfoService.add(userInfo);
    }
    //手机号登录
    @RequestMapping("/phone")
    public ResultVo pohone(@RequestBody UserInfo userInfo){
        return userInfoService.phone(userInfo);
    }
    //忘记密码
    @RequestMapping("/password")
    public ResultVo password(@RequestBody UserInfo userInfo){
        return userInfoService.password(userInfo);
    }
    //修改个人信息
    @RequestMapping("/updateuser")
    public ResultVo update(@RequestBody UserInformationInfo userInfo){
        return userInfoService.updateuser(userInfo);
    }
    //头像上传
    @RequestMapping("/updateimg")
    public  String updateimg(MultipartFile file) throws Exception {
        String imgser = AliPicUtils.upload(file);
        System.out.println(imgser+"+++++");
        return imgser;
    }
    //身份证正面上传
      static String plusImgs;
//    @RequestMapping("/plusImg")
//    public ReVo plusImg(MultipartFile plusImg) throws Exception {
//        String imgser = AliPicUtils.upload(plusImg);
//        ReVo resultVo = SfzUtis.postForm(imgser);
//        plusImgs = imgser;
//        resultVo.setImgser(imgser);
//        System.out.println(plusImgs+"+++++++++++++++++");
//        return resultVo;
//    }
    //身份证正面上传加返回个人用户信息
    @RequestMapping("/plusImg")
    public ReVo plusImg(MultipartFile plusImg) throws Exception {
        return userInfoService.update(plusImg);
    }
    //身份证背面上传
    static String minusImgs;
//    @RequestMapping("/minusImg")
//    public ReVo minusImg(MultipartFile minusImg) throws Exception {
//        String imgser = AliPicUtils.upload(minusImg);
//        ReVo resultVo = SfzUtis.postForm(imgser);
//        minusImgs = imgser;
//        resultVo.setImgser(imgser);
//        return resultVo;
//    }

    //身份证背面上传
    @RequestMapping("/minusImg")
    public ReVo minusImg(MultipartFile minusImg) throws Exception {
        return userInfoService.updatemin(minusImg);
    }



    //上传身份证
//    @RequestMapping("/imgsfz")
//    public ResultVo imgsfz(String code){
//        UserInformationInfo userInformationInfo = new UserInformationInfo();
//        userInformationInfo.setMinusImg(minusImgs);
//        userInformationInfo.setPlusImg(plusImgs);
//        userInformationInfo.setCode(code);
//        return userInfoService.imgsfz(userInformationInfo);
//    }
    //上传身份证和修改个人用户信息
    @RequestMapping("/imgsfz")
    public ResultVo imgsfz(String code) throws ParseException {
        return userInfoService.imgsfz(code);
    }

    //退出
    @RequestMapping("/delete")
    public ResultVo delete(String code){
        redisTemplate.delete(code);
        return userInfoService.delete(code);
    }
    //修改后刷新个人详情页面
    @RequestMapping("/findUserByCode")
    private ResultVo findUserByCode(String code){
        return userInfoService.getusercode(code);
    }


    @RequestMapping("/getCode")
    public UserVo getCode(String code){
        return userInfoService.getCode(code);
    }

}
